{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([[1.        , 0.        , 0.94362745, 0.35869565, 0.29166667,\n",
       "         0.75      , 0.75      , 0.        , 0.66666667, 1.        ,\n",
       "         1.        , 1.        , 0.        , 0.        , 0.        ,\n",
       "         0.75      , 1.        , 0.6       , 0.09438202, 0.        ,\n",
       "         0.        ],\n",
       "        [0.        , 0.        , 0.96078431, 0.47826087, 0.20833333,\n",
       "         0.        , 0.        , 0.66666667, 0.33333333, 0.6       ,\n",
       "         1.        , 0.5       , 0.        , 0.        , 0.        ,\n",
       "         1.        , 0.4       , 0.66666667, 0.95505618, 0.66666667,\n",
       "         0.1980198 ],\n",
       "        [1.        , 0.        , 0.93872549, 0.2173913 , 0.25      ,\n",
       "         0.25      , 0.25      , 0.5       , 0.33333333, 0.6       ,\n",
       "         0.75      , 0.25      , 0.        , 0.        , 0.        ,\n",
       "         0.25      , 0.2       , 0.44      , 0.0752809 , 0.        ,\n",
       "         0.        ],\n",
       "        [0.        , 1.        , 0.95833333, 0.89130435, 0.875     ,\n",
       "         1.        , 0.25      , 1.        , 0.66666667, 0.4       ,\n",
       "         1.        , 1.        , 0.33333333, 0.66666667, 0.58823529,\n",
       "         0.75      , 0.        , 0.64      , 0.08089888, 1.        ,\n",
       "         0.52475248],\n",
       "        [1.        , 0.        , 0.91421569, 0.56521739, 0.36458333,\n",
       "         0.        , 0.        , 1.        , 0.66666667, 0.        ,\n",
       "         0.        , 0.        , 0.        , 0.        , 0.        ,\n",
       "         0.        , 0.        , 0.98666667, 0.08314607, 0.        ,\n",
       "         0.        ]]),\n",
       " array([0, 0, 1, 0, 0]),\n",
       " (366, 21),\n",
       " (366,))"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "\n",
    "\n",
    "#加载数据\n",
    "def load_data():\n",
    "    with open('病马数据.csv') as fr:\n",
    "        lines = fr.readlines()\n",
    "\n",
    "    x = np.empty((len(lines), 21), dtype=float)\n",
    "    y = np.empty(len(lines), dtype=int)\n",
    "    for i in range(len(lines)):\n",
    "        line = lines[i].strip().split(',')\n",
    "        x[i] = line[:21]\n",
    "        y[i] = line[21]\n",
    "\n",
    "    #数据整形\n",
    "    for i in range(x.shape[1]):\n",
    "        #取出一列数据\n",
    "        xi = x[:, i]\n",
    "\n",
    "        #最小值是0\n",
    "        xi -= xi.min()\n",
    "\n",
    "        #最大值是1\n",
    "        xi /= xi.max()\n",
    "\n",
    "        x[:, i] = xi\n",
    "\n",
    "    return x, y\n",
    "\n",
    "\n",
    "w = np.ones(21)\n",
    "b = 0\n",
    "\n",
    "x, y = load_data()\n",
    "\n",
    "x_min = x.min(axis=0)\n",
    "x_max = x.max(axis=0)\n",
    "\n",
    "x[:5], y[:5], x.shape, y.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9999630178591576"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def model(x):\n",
    "\n",
    "    #计算模型\n",
    "    out = x.dot(w) + b\n",
    "\n",
    "    #激活函数,把数据压缩到0-1之间\n",
    "    out = np.exp(out) / (1 + np.exp(out))\n",
    "\n",
    "    return out\n",
    "\n",
    "\n",
    "pred = model(x[0])\n",
    "pred"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.9999630178591576"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求误差\n",
    "def loss(pred, y):\n",
    "    return y - pred\n",
    "\n",
    "\n",
    "l = loss(pred, y[0])\n",
    "l"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "138.62601212775115"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def total_loss():\n",
    "    _sum = 0\n",
    "    for xi, yi in zip(x, y):\n",
    "        l = loss(model(xi), yi)\n",
    "        _sum += np.power(l, 2)\n",
    "    return _sum\n",
    "\n",
    "\n",
    "total_loss()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array([-0.99996302, -0.        , -0.94359255, -0.35868239, -0.29165588,\n",
       "        -0.74997226, -0.74997226, -0.        , -0.66664201, -0.99996302,\n",
       "        -0.99996302, -0.99996302, -0.        , -0.        , -0.        ,\n",
       "        -0.74997226, -0.99996302, -0.59997781, -0.09437853, -0.        ,\n",
       "        -0.        ]),\n",
       " -0.9999630178591576)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#求梯度\n",
    "def gradient(loss, x):\n",
    "\n",
    "    #w的梯度是抄书的,我也不知道为什么是这么算\n",
    "    #简单理解,就是x0*loss + x1*loss = gradient\n",
    "    #也就是说,loss决定了方向和步长,x的值决定了另一个方向和步长.\n",
    "    g_w = loss * x\n",
    "\n",
    "    #这个是我自己写的,简单的求和就完事了\n",
    "    g_b = loss.sum()\n",
    "\n",
    "    return g_w, g_b\n",
    "\n",
    "\n",
    "gradient(l, x[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "([1, 2, 3, 4, 5],\n",
       " [72.56915176914084,\n",
       "  68.79323015492157,\n",
       "  68.02287161064466,\n",
       "  67.82534679011837,\n",
       "  67.6771475233982])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#训练\n",
    "lr = 1e-1\n",
    "losses = []\n",
    "steps = []\n",
    "for i in range(40):\n",
    "    for j in range(len(x)):\n",
    "        xi, yi = x[j], y[j]\n",
    "        pred = model(xi)\n",
    "        l = loss(pred, yi)\n",
    "        g_w, g_b = gradient(l, xi)\n",
    "        w += g_w * lr\n",
    "        b += g_b * lr\n",
    "\n",
    "    #lr递减\n",
    "    lr /= 1.2\n",
    "\n",
    "    #防止变成0\n",
    "    lr += 1e-5\n",
    "\n",
    "    steps.append((i + 1))\n",
    "    losses.append(total_loss())\n",
    "\n",
    "steps[:5], losses[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAedklEQVR4nO3de3Rcdb338fd3Jpnc2qRJmtI7pbQUaaEXUhQoHKHcRRA8SEG0XLQeRYTjeVQ8+rB0nfNw0MdbXT6iWKiiCBwQvKBWkaOACoX0QqG0pbSltPaW3tukuc73+WN20jSkzaTNZM/OfF5rZc3Mb2YyH7fwyeY3e/+2uTsiIhI9sbADiIjI0VGBi4hElApcRCSiVOAiIhGlAhcRiai8vvywwYMH+5gxY/ryI0VEIm/RokXb3b2q83ifFviYMWOoqanpy48UEYk8M1vf1bimUEREIkoFLiISUSpwEZGIUoGLiESUClxEJKJU4CIiEaUCFxGJqEgU+DMrtvL9v7wZdgwRkawSiQJ/fvV27v3zmrBjiIhklUgUeEVJgn2NLTS1JMOOIiKSNSJT4AC76ptCTiIikj0iVeA761TgIiJtVOAiIhEViQKvVIGLiLxDJAq8XAUuIvIOkSjwQUX5mMEOFbiISLtIFHhePEZZUT67VOAiIu0iUeCQ+iJTUygiIgdFp8CLVeAiIh1Fp8C1By4icohuL2psZhOARzsMjQXuAkYA7weagDXATe6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RCJKBS4iElEqcBGRiFKBi4hElApcRCSiVOAiIhH1/wFFLwfizTxYeQAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "from matplotlib import pyplot as plt\n",
    "\n",
    "# 第一个是横坐标的值，第二个是纵坐标的值\n",
    "plt.plot(steps, losses)\n",
    "# 必要方法，用于将设置好的figure对象显示出来\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.7185792349726776"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#预测\n",
    "correct = 0\n",
    "for xi, yi in zip(x, y):\n",
    "    #计算模型\n",
    "    pred = model(xi)\n",
    "\n",
    "    #I函数\n",
    "    pred = 1 if pred > 0.5 else 0\n",
    "\n",
    "    if pred == yi:\n",
    "        correct += 1\n",
    "\n",
    "#在这个数据集上,这个表现就是极限了,这里实际已经严重过拟合了\n",
    "correct / len(x)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
